//
//  ShellCoinDetailViewModel.m
//  ShellWallert
//
//  Created by lvzhao on 2020/5/10.
//  Copyright © 2020 VV. All rights reserved.
//

#import "ShellCoinDetailViewModel.h"

@implementation ShellCoinDetailViewModel
//获取详情
- (void)getShellCoinDetail{
    
    @weakify(self);
    [LZNetworkingManager lz_request:@"get" url:kCrowdInfo params:@{@"crowdId":self.coinModel.modelId?:@""} success:^(id  _Nullable responseObject) {
        @strongify(self);
        if([responseObject[kResultStatus] isEqualToString:kCode]){
            self.coinModel = [ShellCoinModel mj_objectWithKeyValues:responseObject[kResultData]];
        }
        [self.reloadSubject sendNext:@(3)];
    } failure:^(NSError * _Nullable error) {} isLoading:YES isFailTip:YES];
    
}

/**
 认购
 */
- (void)crowdBuy:(NSString *)amount payPassword:(NSString *)payPassword{
    
    NSDictionary *params = @{@"crowdId":self.coinModel.modelId?:@"",
                             @"payPassword":payPassword?:@"",
                             @"amount":amount?:@""};
    
    [LZNetworkingManager lz_request:@"post" url:kCrowdBuy params:params success:^(id  _Nullable responseObject) {
        if([responseObject[kResultStatus] isEqualToString:kCode]){
            showDelayedDismissTitle(LZLocalizedString(@"预约成功"), nil);
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [LZTool.currentViewController.navigationController popViewControllerAnimated:YES];
            });
        }
    } failure:^(NSError * _Nullable error) {} isLoading:YES isFailTip:YES];
}
@end
